From 1d77bc94c2b41ec266d2b7e4db1203f6fec536fd Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 6 Jan 2012 06:16:05 +0000 Subject: [PATCH] * Cleanup for r108175: made if easier for extensions to interact with each other in TitleReadWhitelist hook. A handler can set $whitelisted to true to whitelist the page or it can set it to false and return false (most restrictive wins). * Added some hook doc comments. --- docs/hooks.txt | 5 ++--- includes/GlobalFunctions.php | 2 +- includes/Hooks.php | 2 +- includes/Title.php | 15 +++++++-------- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/docs/hooks.txt b/docs/hooks.txt index b1a153c8a1..b5d0ad53b5 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -1928,11 +1928,10 @@ $redirid: database ID of the created redirect 'TitleReadWhitelist': called at the end of read permissions checks, just before adding the default error message if nothing allows the user to read the page. - Return false will prevent core from adding its error message, but you need - to removed extensions' error messages from $errors yourself. + If a handler wants a title to *not* be whitelisted, it should also return false. $title: Title object being checked against $user: Current user object -&$errors: errors +&$whitelisted: Boolean value of whether this title is whitelisted 'UndeleteForm::showHistory': called in UndeleteForm::showHistory, after a PageArchive object has been created but before any further processing is done. diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 231dc65485..db2ff35cd8 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -3754,7 +3754,7 @@ function wfGetParserCacheStorage() { * * @param $event String: event name * @param $args Array: parameters passed to hook functions - * @return Boolean + * @return Boolean True if no handler aborted the hook */ function wfRunHooks( $event, $args = array() ) { return Hooks::run( $event, $args ); diff --git a/includes/Hooks.php b/includes/Hooks.php index bfec82e984..e1c1d50b5a 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -86,7 +86,7 @@ class Hooks { * * @param $event String: event name * @param $args Array: parameters passed to hook functions - * @return Boolean + * @return Boolean True if no handler aborted the hook */ public static function run( $event, $args = array() ) { global $wgHooks; diff --git a/includes/Title.php b/includes/Title.php index 86aa4ee668..cb36e1a49b 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1965,12 +1965,11 @@ class Title { * @return Array list of errors */ private function checkReadPermissions( $action, $user, $errors, $doExpensiveQueries, $short ) { - global $wgWhitelistRead; + global $wgWhitelistRead, $wgGroupPermissions, $wgRevokePermissions;; static $useShortcut = null; # Initialize the $useShortcut boolean, to determine if we can skip quite a bit of code below if ( is_null( $useShortcut ) ) { - global $wgGroupPermissions, $wgRevokePermissions; $useShortcut = true; if ( empty( $wgGroupPermissions['*']['read'] ) ) { # Not a public wiki, so no shortcut @@ -1993,7 +1992,6 @@ class Title { } $whitelisted = false; - if ( $useShortcut ) { # Shortcut for public wikis, allows skipping quite a bit of code $whitelisted = true; @@ -2036,11 +2034,12 @@ class Title { } } - # If the user is allowed to read tge page; don't call the hook - if ( $whitelisted && !count( $errors ) ) { - return array(); - } elseif ( wfRunHooks( 'TitleReadWhitelist', array( $this, $user, &$errors ) ) && !$whitelisted ) { - $errors[] = $this->missingPermissionError( $action, $short ); + if ( !$whitelisted ) { + # If the title is not whitelisted, give extensions a chance to do so... + wfRunHooks( 'TitleReadWhitelist', array( $this, $user, &$whitelisted ) ); + if ( !$whitelisted ) { + $errors[] = $this->missingPermissionError( $action, $short ); + } } return $errors; -- 2.20.1